package com.example.demo.controller;

import com.qiniu.util.Auth;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/qiniu")
public class QiniuController {

  private static final String ACCESS_KEY = "xxxx";

  private static final String SECRET_KEY = "xxxx";

  private static final String BUCKET = "caomudai";

  @RequestMapping("/getUploadToken")
  public String getUploadToken() {
    Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
    String upToken = auth.uploadToken(BUCKET);
    System.out.println(upToken);
    return upToken;
  }

  //获取带有目标文件名的token
  @RequestMapping("/getUploadToken2")
  public String getUploadToken2(@RequestParam(value = "targetName") String targetName) {
    Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
    String upToken = auth.uploadToken(BUCKET, targetName);
    System.out.println(upToken);
    return upToken;
  }

}
